import csv

from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts.globals import ThemeType

with open('./file/time_hour.csv') as csvfile:
    reader = csv.reader(csvfile)
    x = [str(row[0]) for row in reader]
    print(x)
with open('./file/time_hour.csv') as csvfile:
    reader = csv.reader(csvfile)
    y = [float(row[1]) for row in reader]
    print(y)
num = y
lab = x
(Pie(init_opts=opts.InitOpts(width='1700px', height='450px', theme=ThemeType.LIGHT))
 .set_global_opts(
    title_opts=opts.TitleOpts(title="雪中悍刀行近日评论统计", title_textstyle_opts=opts.TextStyleOpts(font_size=27)),
    legend_opts=opts.LegendOpts(pos_top="10%", pos_left="1%")
    )
 .add(series_name='', center=[280, 270], data_pair=[(j, i) for i, j in zip(num, lab)])
 .add(series_name='', center=[845, 270], data_pair=[(j, i) for i, j in zip(num, lab)], radius=['40%', '75%'])
 .add(series_name='', center=[1380, 270], data_pair=[(j, i) for i, j in zip(num, lab)], rosetype='radius')
 ).render('./Html/pie_pyecharts.html')
